// ChatServerDoc.cpp : implementation file
//

#include "stdafx.h"
#include "Chat.h"
#include "ChatServerDoc.h"
#include "NatPunchthroughServer.h"

// CChatServerDoc

IMPLEMENT_DYNCREATE(CChatServerDoc, CChatBaseDoc)

CChatServerDoc::CChatServerDoc()
: m_pNatPunchThroughServer(NULL)
{
}

BOOL CChatServerDoc::OnNewDocument()
{
	if (!CChatBaseDoc::OnNewDocument())
		return FALSE;

	m_pNatPunchThroughServer = new NatPunchthroughServer;
	AttachRaknetPlugin(m_pNatPunchThroughServer);

	return TRUE;
}

CChatServerDoc::~CChatServerDoc()
{
	if (m_pNatPunchThroughServer)
	{
		DetachRaknetPlugin(m_pNatPunchThroughServer);
		delete m_pNatPunchThroughServer;
		m_pNatPunchThroughServer = NULL;
	}
}


BEGIN_MESSAGE_MAP(CChatServerDoc, CChatBaseDoc)
END_MESSAGE_MAP()


// CChatServerDoc diagnostics

#ifdef _DEBUG
void CChatServerDoc::AssertValid() const
{
	CChatBaseDoc::AssertValid();
}

#ifndef _WIN32_WCE
void CChatServerDoc::Dump(CDumpContext& dc) const
{
	CChatBaseDoc::Dump(dc);
}
#endif
#endif //_DEBUG

#ifndef _WIN32_WCE
// CChatServerDoc serialization

void CChatServerDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

bool CChatServerDoc::StartUpRaknet( unsigned short maxConnections, int _threadSleepTimer, SocketDescriptor *socketDescriptors, unsigned socketDescriptorCount )
{	
	return __super::StartUpRaknet(maxConnections, _threadSleepTimer, socketDescriptors, socketDescriptorCount);
}
#endif

// CChatServerDoc commands
